package com.briup.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.demo.bean.XcdBuyer;
import com.briup.demo.common.Response;
import com.briup.demo.service.XcdBuyerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "客户信息管理")
@RestController
@RequestMapping("/buyer")
public class XcdBuyerController {
	@Autowired
	private XcdBuyerService buyerService;

	@ApiOperation(value = "新增或修改客户信息",notes = "用户")
	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(XcdBuyer buyer){	
		int b = buyerService.saveOrUpdateCmsCategory(buyer);
		if(b==1) return Response.ok("更新信息成功！");
		else  return Response.error("插入信息成功！");
	}	

    @ApiOperation("按照客户编号查找客户")
    @GetMapping("/selectById")
    public Response<XcdBuyer> selectById(String id)
    {
    	XcdBuyer xb=buyerService.selectById(id);
        return Response.ok(xb);
    }
    
    @ApiOperation("按照客户名查找客户")
    @GetMapping("/selectByName")
    public Response<List<XcdBuyer>> selectByName(String name)
    {
    	List<XcdBuyer> xb=buyerService.selectByName(name);
        return Response.ok(xb);
    }


    @ApiOperation("按客户编号删除客户")
    @DeleteMapping("/deleteById")
    public Response<String> deleteById(String id){
        int num = buyerService.deleteById(id);
        if(num==1) {
        	return Response.ok("删除成功");
        }else {
        	return Response.ok("删除失败");
        }
    }
    
    @ApiOperation("按客户编号批量删除客户")
    @DeleteMapping("/deleteByIds")
    public Response<String> deleteByIds(String[] ids){
    	int num = buyerService.deleteByIds(ids);
    	if(num==0) {
    		return Response.ok("删除失败");
    	}else {
    		return Response.ok("删除"+num+"个客户信息");
    	}
    }
    

    @ApiOperation("显示列表")
    @GetMapping("/selectAll")
    public Response<List<XcdBuyer>> selectAll(){
        return Response.ok(buyerService.selectAll());
    }

}
